{% extends "::base.html.twig" %}
{% block title %}Quizz - {{ quizz.titre }}{% endblock %}

    {% block other %}
        {% if leuser is defined %}
            <h1 style="margin-bottom: 0;"> Quizz {{ quizz.titre }}</h1>
            <h2 style="text-align:left; font-weight: normal; font-size: 11pt; margin-left:0 !important; padding-left:48px;"><a href="{{ path('readUser') }}">Utilisateurs</a> > <a href="{{ path('readAllEleveQuizz',{idUser:leuser.id}) }}">{{leuser.username }}</a> > {{quizz.titre}}  </h2>
        {% else %}
            <h1>Quizz - {{ quizz.titre }}</h1>
        {% endif %}
    {% endblock %}
{% block body %}
    {% if not reponse is defined %}
        <form id="QuizzEleve" action="{{ path('elevecorrection',{quizzId:quizz.id}) }}" method="POST">
            {% set numquestion=0 %}
                {% for item in question %}
                        {% set numquestion=numquestion+1 %}
                    <div class="question">
                        <p class="titre">Question n°{{numquestion}}&nbsp;&nbsp;-&nbsp;&nbsp;{{ item.question }}</p>
                        <div>
                            {% for ch in choix[item.id] %}
                                <p class="ch">
                                    <input type="checkbox"  name="form[{{item.id}}][{{ ch.id }}]"> {{ ch.libelle }}</input>
                                </p> 
                            {% endfor %}
                        </div>
                    </div>
                {% endfor %}
            <input type="submit" class = "btn btn-primary" />
        </form>
    {% else %}
            {% set total=0 %}
            {% set nbtotal=0 %}
            {% set numquestion=0 %}
        <div id="QuizzEleve">
                    {% for item in question %}
                        {% set numquestion=numquestion+1 %}
                         <div class="question">
                            <p class="titre">Question n°{{numquestion}}&nbsp;&nbsp;-&nbsp;&nbsp;{{ item.question }}</p>
                            <div>
                            {% for ch in reponse[item.id] %}
                                {% if ch.choix.points > 0 %}
                                    {% if not ch.sel %}
                                     <p class="error">
                                        <span>Faux</span>
                                        {{ ch.choix.libelle }}

                                        {% set total=total-ch.choix.question.decrementation %}
                                        {% set nbtotal=nbtotal+ch.choix.points %}

                                        <i>-{{ch.choix.question.decrementation}}</i> 
        
                                     </p>
                                    {% else %}
                                     <p class="success">
                                        <span>Bonne réponse</span>

                                        {% set total=total+ch.choix.points %}
                                        {% set nbtotal=nbtotal+ch.choix.points %}

                                        {{ ch.choix.libelle }}  <i> +{{ ch.choix.points }}</i> </p>
                                    {% endif %}
                                {% else %}
                                    {% if ch.sel %}
                                     <p class="error">
                                        <span>Mauvaise Réponse</span>
                                        {{ ch.choix.libelle }}

                                        {% set total=total-ch.choix.question.decrementation %}
                                        {% set nbtotal=nbtotal+ch.choix.points %}

                                        <i> -{{ch.choix.question.decrementation}}</i> 
                                     </p>
                                    {% else %}
                                     <p class="succ-min">
                                        <span>Ok</span>
                                        {% set total=total+ch.choix.points %}
                                        {% set nbtotal=nbtotal+ch.choix.points %}
                                        {{ ch.choix.libelle }}
                                    </p>
                                    {% endif %}
                                {% endif %}
                            {% endfor %}
                                </div>
                            </div>
                    {% endfor %}
                    <div class="total">
                        <span style="font-size:20pt;">
                            Total 
                            {% if total <0 %}
                                0
                            {% else %}
                                {{ total/nbtotal*20 }}
                            {% endif %}
                        </span>
                        <span style="font-size:16pt">/</span>
                        <span style="font-size:18pt">20</span>
                    </div>
            </div>
    {% endif %}
{% endblock %}